home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Library
/
RoseWare - Network Support Library.iso
/
apidev
/
mhs_c.arc
/
INPOST.ARC
/
PARSE.C
< prev
Wrap
C/C++ Source or Header
|
1988-06-27
|
2KB
|
103 lines
/* ******************************** PARSE.C ******************************* */
#include "cctypes.h"
#define LINE_LEN_MAX 81
#define FIRST_WORD_SIZE 37
char currentLine[LINE_LEN_MAX];
extern int InFile;
extern int comType;
extern char messageBuffer[];
void UpperCase();
void AddCurrentLineToMessageBuffer();
int GetNextLine();
void GetFirstWord();
int Parse()
{
int returnCode = NO_ERROR, ccode, bytes = 0;
char firstWord[FIRST_WORD_SIZE];
while (1) { /* as long as we're getting bytes... */
bytes = GetNextLine(); /* uses InFile and currentLine */
if ( bytes == 0 ) /* EOF */
break;
/* else */
GetFirstWord(firstWord); /* gets the first word of the current line */
ccode = GetCommandType(firstWord);
if ( ccode != -1 )
CreateMCBLine(ccode); /* ccode is the switch table index */
else
AddCurrentLineToMessageBuffer();
} /* end while */
return(returnCode);
}
void AddCurrentLineToMessageBuffer()
{
char temp[135];
sprintf(temp, "%s\15\12", currentLine);
strcat(messageBuffer, temp);
}
int GetNextLine()
{
int bytesRead = 0, temp;
char ch[1];
ch[0] = ' ';
currentLine[0] = '\0';
while (ch[0] != 13) {
temp = read(InFile, ch, 1);
if ( temp == 0 )
break;
currentLine[bytesRead++] = ch[0];
}
if ( temp )
temp = read(InFile, ch, 1); /* ch should be 10 here */
currentLine[bytesRead-1] = '\0'; /* null terminate where we got the 13 */
return(bytesRead);
}
void GetFirstWord(firstWord)
char *firstWord;
{
firstWord[0] = '\0';
stptok(currentLine, firstWord, FIRST_WORD_SIZE, " ");
}
void UpperCase(s)
char *s;
{
int i = 0;
while ( s[i] != '\0' ) {
s[i] = islower(s[i]) ? toupper(s[i]) : s[i];
i++;
}
}
int GetCommandType(command)
char *command;
{
int i;
if ( strlen(command) ) {
for ( i = 0; CommandTypes[i]; i++ ) {
if ( strcmp(command, CommandTypes[i]) == 0 ) {
comType = i;
return(i);
}
}
}
return(BADCOMMAND);
}